package com.nus.fellowmark.common.utils;

import org.springframework.beans.BeanUtils;
import com.google.common.collect.Lists;
import java.util.List;

/**
 * @author Ruoyi Chen
 * @email chenruoyisz@gmail.com
 * @create 2023/2/11
 */
public class ClassUtil {
    public static <P, T> P copyProperties(Class<P> target, T source) {
        P p = BeanUtils.instantiateClass(target);
        BeanUtils.copyProperties(source, p);
        return p;
    }

    /**
     * copy list
     *
     * @param source
     * @param target
     * @param <F>
     * @param <T>
     * @return
     */
    public static <T, F> List<T> copyList(List<F> source, Class<T> target) {
        return Lists.transform(source, t -> copyProperties(target, t));
    }

}
